﻿
@{
    ViewBag.Title = "DjAdd";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}



@section head{
    <style type="text/css">
        #outermost_container { /*页面最外层容器样式*/
            width: 100%;
            height: 100%;
        }

        /*左右两个容器的样式*/
        #left_container {
            width: 50%;
            height: 100%;
            float: left;
        }

        #right_container {
            width: 50%;
            height: 100%;
            float: left;
        }

        /*上下两个容器的样式*/
        #top_container {
            width: 100%;
            height: 70%;
        }

        #bottom_container {
            width: 100%;
            height: 30%;
        }
    </style>
}

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>创建维修单据</legend>
</fieldset>

<div>
    <!--单据添加功能按钮-->
    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add" style="margin-left:0.5%" id="BtnAddDj"> 创建 </button>
</div>

<div id="show_outermost_container" style="display: none; ">
    <div style="margin-top:1%;">

        <form id="DjMsgForm" lay-filter="DjMsgList" class="layui-form">

            <div class="layui-form-item">
                <div style="float:left; margin-left: 5%; width: 45%;">
                    <label class="layui-form-label">产品名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="product_name" lay-verify="required" placeholder="请输入产品名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div style="float:left; margin-right: 5%; width: 45%;">
                    <label class="layui-form-label">产品型号</label>
                    <div class="layui-input-block">
                        <input type="text" name="product_model" placeholder="请输入产品型号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div style="margin-left: 5%; margin-right: 5%;">
                    <label class="layui-form-label">产品序列号</label>
                    <div class="layui-input-block">
                        <input type="text" name="product_serial" lay-verify="required" placeholder="请输入产品序列号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <div style="margin-left: 5%; margin-right: 5%;">
                    <label class="layui-form-label">问题描述</label>
                    <div class="layui-input-block">
                        <textarea name="problem_description" placeholder="请描述问题" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div style="margin-left: 5%;">
                    <label class="layui-form-label" style="float: left;">
                        上传图片
                        <i class="layui-icon layui-icon-picture" style="width: 10px; height: 10px;"></i>
                    </label>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <label class="layui-form-label"></label>
                        <button type="button" class="layui-btn" id="BtnSave">提交</button>
                    </div>
                </div>
            </div>

            <button type="submit" id="formAddsubmit" class="layui-btn" lay-submit lay-filter="formAddVerify" style="display:none;">隐藏提交按钮</button>

        </form>

    </div>
</div>


<script type="text/javascript">
    var table;

    layui.use(['form', 'table', 'upload', 'layer'], function () {
        var IsValidate = 0;
        var form = layui.form;

        //拦截form提交消息
        form.on('submit(formAddVerify)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            IsValidate = 1;
            return false;
        });

        $("#BtnAddDj").on("click", function () {
            index = layer.open({
                type: 1,
                area: ['80%', '80%'],
                content: $("#show_outermost_container") //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            });
        });

        //新增单据保存
        $("#BtnSave").on("click", function () {
            $("#formAddsubmit").click();
            if (IsValidate == 1) {
                IsValidate = 0;
            } else {
                return;
            }
            var obj = $("#DjMsgForm").serializeArray();
            var data = {};
            $.each(obj, function (i, v) {
                data[v.name] = v.value;
            });
            $.ajax({
                type: "POST",
                url: "/DataExchange/DjAdd",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('新增成功', { icon: 6, time: 1000 });
                        layer.close(index);
                        table.reload("UserTable");
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });

    });

    

</script>
